home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #21 (Jun 87) / Corrected format Source Files / BuffStuff.a next >
Text File  |  1987-05-07  |  3KB  |  104 lines

  1. ;********************** File:BuffStuff.a ************************
  2. ;****************************************************************
  3. ;
  4. ; This file contains a couple of subroutines that are used for 
  5. ; manipulating the buffers.
  6.  
  7.     BLANKS    ON
  8.     
  9.     IMPORT        (BadB_List,BadB_Num,BadB_Out):DATA
  10.     INCLUDE        'FormatEqu.a'        
  11.     
  12.  
  13. ; PROC ClearBuff    
  14. ;
  15. ; This subroutine is used to clear a buffer.  It gets the address
  16. ; in A0 and the length in bytes in D0 (long word value).
  17.  
  18. ClearBuff    PROC    EXPORT    ;subroutine for export to other
  19.                             ;moduals at link time.
  20.     
  21.     movem.l    D0/A0,-(SP)        ;save registers
  22.     subq    #1,D0            ;D0=count-1; branch after clr.b
  23.     blt.s    exit            ;exit if passed buffer length =0
  24.     
  25. buf_loop
  26.     clr.b    (A0,D0.L)            ;clear the byte
  27.     dbra    D0,buf_loop            ;branch when D0>0
  28. exit
  29.     movem.l    (SP)+,D0/A0            ;restore the registers
  30.     rts
  31.  
  32.     ENDPROC
  33.  
  34. ; PROC OutBuff
  35. ;
  36. ; OutBuff takes our list of bad blocks and reformats so it can be 
  37. ; used as the defect data block that gets transfered after the 
  38. ; format command. First we place the size of the defect data 
  39. ; block minus the 4 byte header in byte 3. Then we start loading
  40. ; in the bad block records.  They must have aready been sorted 
  41. ; in order of increasing cylinder number.  The fields in each
  42. ; record are of the form: 3 bytes for the cylinder, one byte for
  43. ; the head number and a long word for the bytes from index value. 
  44. ;
  45. ; Registers:
  46. ; A0    Points to curent position in BadB_List 
  47. ;            (our sorted list of bad blocks used for input)
  48. ; A1    Points to current position in BadB_Out
  49. ;            (our output buffer used in formatting)
  50. ; D1    Scratch
  51. ; D0    Loop index
  52.  
  53. OutBuff        PROC    EXPORT    
  54.         
  55. ; Equates for offset at beginning of bad block output buffer:
  56. ByteCount    EQU        3
  57.  
  58.  
  59.  
  60.  
  61.     movem.l    D0-D1/A0-A1,-(A7)    ;save registers on stack
  62.  
  63. ; Clear the output buffer before we start transfering records.
  64.     lea        BadB_Out(A5),A0        
  65.     move.l    #MaxBBOutLen,D0
  66.     jsr        ClearBuff
  67.     
  68.     move.l    BadB_Num(A5),D0        ;get the number of defects
  69.     beq        exit                ;exit if it's zero
  70.     subq.l    #1,D0                ;adjust D0 (dbra after transfer)
  71.  
  72.     lea        BadB_List(A5),A0    ;initialize A0
  73.     lea        BadB_Out(A5),A1        ;initialize A1
  74.     clr.l    D1                    ;clear scratch
  75.     move.l    BadB_Num(A5),D1
  76.     lsl.l    #3,D1                ;multipy count by 8 bytes
  77.     move.b    D1,ByteCount(A1)    ;place LSB of count in header
  78.     adda.l    #4,A1                ;incr output pointer to 1st rec.
  79.         
  80. loop
  81.     move.l    CylBBuff(A0),D1        ;load cylinder# into scratch area
  82.     move.b    D1,CylOut_LB(A1)    ;move low byte into record
  83.     lsr.l    #8,D1                
  84.     move.b    D1,CylOut_MB(A1)    ;move middle byte into record
  85.     lsr.l    #8,D1
  86.     move.b    D1,CylOut_HB(A1)    ;move high byte into record
  87.     
  88.     move.b    3+HeadBBuff(A0),HeadOut(A1)    
  89.                                 ;move head number into record, 
  90.                                     ;moving byte value of long
  91.     
  92.     move.l    BFIBBuff(A0),BFIOut(A1)
  93.                                 ;transfer Byte_From_Index value
  94.         
  95.     adda.l    #16,A0                ;A0 points to next input record
  96.     adda.l    #8,A1                ;A1 points to next output record
  97.     dbra    D0,Loop                ;decrement loop counter & repeat
  98.     
  99. exit    
  100.     movem.l    (A7)+,D0-D1/A0-A1    ;restore registers
  101.     rts
  102.     
  103.     ENDPROC
  104.     END